package com.ruoyi.tcustomer.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.websocker.MessageBean;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tcustomer.domain.TCustomer;
import com.ruoyi.tcustomer.service.ITCustomerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客服管理Controller
 *
 * @author ruoyi
 * @date 2024-11-08
 */
@RestController
@RequestMapping("/tcustomer/tcustomer")
public class TCustomerController extends BaseController
{
    @Autowired
    private ITCustomerService tCustomerService;

    /**
     * 查询客服管理列表
     */
    @PreAuthorize("@ss.hasPermi('tcustomer:tcustomer:list')")
    @GetMapping("/list")
    public TableDataInfo list(TCustomer tCustomer)
    {
        startPage();
        List<TCustomer> list = tCustomerService.selectTCustomerList(tCustomer);
        return getDataTable(list);
    }

    /**
     * 导出客服管理列表
     */
    @PreAuthorize("@ss.hasPermi('tcustomer:tcustomer:export')")
    @Log(title = "客服管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCustomer tCustomer)
    {
        List<TCustomer> list = tCustomerService.selectTCustomerList(tCustomer);
        ExcelUtil<TCustomer> util = new ExcelUtil<TCustomer>(TCustomer.class);
        util.exportExcel(response, list, "客服管理数据");
    }

    /**
     * 获取客服管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('tcustomer:tcustomer:query')")
    @GetMapping(value = "/{customerId}")
    public AjaxResult getInfo(@PathVariable("customerId") Long customerId)
    {
        return success(tCustomerService.selectTCustomerByCustomerId(customerId));
    }

    /**
     * 新增客服管理
     */
    @PreAuthorize("@ss.hasPermi('tcustomer:tcustomer:add')")
    @Log(title = "客服管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCustomer tCustomer)
    {
       return tCustomerService.insertTCustomer(tCustomer);
//        return toAjax(tCustomerService.insertTCustomer(tCustomer));
    }

    /**
     * 修改客服管理
     */
    @PreAuthorize("@ss.hasPermi('tcustomer:tcustomer:edit')")
    @Log(title = "客服管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCustomer tCustomer)
    {
        return toAjax(tCustomerService.updateTCustomer(tCustomer));
    }

    /**
     * 删除客服管理
     */
    @PreAuthorize("@ss.hasPermi('tcustomer:tcustomer:remove')")
    @Log(title = "客服管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{customerIds}")
    public AjaxResult remove(@PathVariable Long[] customerIds)
    {
        return toAjax(tCustomerService.deleteTCustomerByCustomerIds(customerIds));
    }
    @PreAuthorize("@ss.hasPermi('tcustomer:tcustomer:repeat')")
    @Log(title = "客服管理", businessType = BusinessType.UPDATE)
    @GetMapping("/repeat/{id}")
    public AjaxResult repeat(@PathVariable("id") Long id)
    {
        return tCustomerService.repeatPassword(id);
    }

    @GetMapping("/getMessage")
    public List<MessageBean> getMessage(@RequestParam("customerId") Long customerId,@RequestParam("userId")Long userId){
        return tCustomerService.findCustomerMessageById(customerId,userId);
    }
}
